﻿using Microsoft.SharePoint;
using RoketSolutions.SP2010.ImageRotatorWebPart.Constants;
using RoketSolutions.SP2010.Infrostructure.Common;
using RoketSolutions.SP2010.Infrostructure.Data.Entities;
using RoketSolutions.SP2010.Infrostructure.Common.Extensions;

namespace RoketSolutions.SP2010.ImageRotatorWebPart.Data.Entities
{
    public enum TargetType { Self, Tab }

    public class ImageRotatorItem : ListEntityBase
    {
        public ImageRotatorItem(SPListItem item) : base(item)
        {
        }

        public string ImageUrl
        {
            get { return string.Format("{0}/{1}", Item.ParentList.RootFolder.ServerRelativeUrl, Item.Name); }
        }

        public string LinkUrl
        {
            get { return Item.GetString(ImageRotatorFields.LinkUrl.Name); }
            set { Item.SetProperty(ImageRotatorFields.LinkUrl.Name, value); }
        }

        public TargetType LinkTarget
        {
            get { return EnumView<TargetType>.Parse(Item.GetString(ImageRotatorFields.LinkTarget.Name), TargetType.Tab); }
            set { Item.SetProperty(ImageRotatorFields.LinkTarget.Name, value.ToString()); }
        }
    }
}